#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
#include <time.h>
using namespace std;

class Solution {
public:
    void qfind(vector<int>& nums, int begin, int end, int k)
    {
        if (k == 0) return;
        int left = begin - 1, right = end + 1, i = begin;
        int keyi = rand() % (end - begin + 1) + begin;
        int key = nums[keyi];
        while (i < right)
        {
            if (nums[i] < key) swap(nums[++left], nums[i++]);
            else if (nums[i] == key) ++i;
            else swap(nums[--right], nums[i]);
        }
        int a = left - begin + 1;
        int b = right - left - 1;
        if (a > k) return qfind(nums, begin, left, k);
        else if (a + b >= k) return;
        else qfind(nums, right, end, k - a - b);
    }
    vector<int> inventoryManagement(vector<int>& stock, int cnt) {
        srand(time(nullptr));
        qfind(stock, 0, stock.size() - 1, cnt);
        return { stock.begin(),stock.begin() + cnt };
    }
};